package com.example.idea.exception;

import com.example.idea.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 功能：自定义异常提醒
 * 作者：妙笔生花
 * 日期：2024/9/6 15:09
 */
@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result serviceException(ServiceException e) {
        return Result.error(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result Exception(ServiceException e) {
        e.printStackTrace();
        return Result.error(500,"系统错误");
    }
}
